package com.flame.system.log.controller;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.system.log.controller.vo.OperateLogVo;
import com.flame.system.log.entity.OperateLog;
import com.flame.system.log.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * flame_operate_log 操作日志表
 *
 * @author 吴欣童
 * @since 2023-02-24 22:22:46
 */
@RestController
public class OperateLogController {

    @Autowired
    private OperateLogService operateLogService;

    @HasAuth("operate-log")
    @PostMapping("/system/log/operate/page")
    public PageResult pageOperateLog(@RequestBody OperateLogVo operateLogVo) {
        return PageResult.success(operateLogService.pageOperateLog(operateLogVo));
    }

    @HasAuth("operate-log")
    @PostMapping("/system/log/operate")
    public Result getOperateLog(@RequestBody OperateLog operateLog) {
        return Result.success(operateLogService.getOperateLog(operateLog.getLogId()));
    }

    @HasAuth("operate-log:batch-delete")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/system/log/operate/batch-delete")
    public Result batchDeleteUserLoginLog(@RequestBody List<Long> logIdList) {
        operateLogService.batchDelete(logIdList);
        return Result.success();
    }

    @HasAuth("operate-log:clear")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/system/log/operate/clear")
    public Result clearLog() {
        operateLogService.clear();
        return Result.success();
    }
}
